﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DEMO3.BUS;
using DEMO3.DTO;


namespace DEMO3.GUI
{
    public partial class CaChieu : UserControl
    {
        public CaChieu()
        {
            InitializeComponent();
        }
        private void CaChieu_Load(object sender, EventArgs e)
        {
            DataProvider test = new DataProvider();
            if (!test.OpenConnect())
                Main.Warning();
            else
                LoadData();
            test.CloseConnect();
        }
        private void LoadData()
        {

            CaChieuBUS bus = new CaChieuBUS();
            gc.DataSource = bus.Get();
            DataProvider test = new DataProvider();          
        }
        private void btThem_Click(object sender, EventArgs e)
        {
            CaChieuDTO dto = new CaChieuDTO();
            dto.MaCaChieu = txtMaCaChieu.Text;
            dto.GioBD = DateTime.Parse( mtxtBD.Text);
            dto.GioKT = DateTime.Parse(mtxtKT.Text);
            CaChieuBUS bus = new CaChieuBUS();
            bus.Add(dto);
            LoadData();
        }
        private void btXoa_Click_1(object sender, EventArgs e)
        {
            CaChieuDTO dto = new CaChieuDTO();
            dto.MaCaChieu = gv.GetRowCellValue(gv.FocusedRowHandle, "MaCaChieu").ToString();
            CaChieuBUS bus = new CaChieuBUS();
            bus.Delete(dto);
            LoadData();
        }
       

        private void btSua_Click(object sender, EventArgs e)
        {            
           CaChieuDTO dto = new CaChieuDTO();
           dto.MaCaChieu = txtMaCaChieu.Text;
           dto.GioBD =  DateTime.Parse( mtxtBD.Text);
           dto.GioKT = DateTime.Parse(mtxtKT.Text);
           CaChieuBUS bus = new CaChieuBUS();
            bus.Update(dto);
            LoadData();
        }

        private void gv_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (gv.FocusedRowHandle != gv.RowCount && gv.RowCount != 0)
            {
                txtMaCaChieu.Text = gv.GetRowCellValue(gv.FocusedRowHandle, "MaCaChieu").ToString();
                mtxtBD.Text = gv.GetRowCellValue(gv.FocusedRowHandle, "GioBatDau").ToString();
                mtxtKT.Text = gv.GetRowCellValue(gv.FocusedRowHandle, "GioKetThuc").ToString();
            }
        }

    }
}
